package com.souku.finance.application.base;

import android.app.Activity;
import android.content.Intent;

import java.util.ArrayList;
import java.util.List;

;

/**
 * Created by Administrator on 2016/5/4.
 */
public class ActivityManage {

    public static boolean isRun() {
        return isRun;
    }

    public static void setRun(boolean run) {
        isRun = run;
    }

    private static boolean isRun;

    private static List<Activity> list = new ArrayList<Activity>();

    public static List<Activity> getAll() {
        return list;
    }

    public static void add(Activity activity) {
        list.add(activity);
    }

    public static void remove(Activity activity) {
        list.remove(activity);
    }

    public static void finishSame(Class glass) {
        String str = glass.getName();
        for (Activity a : list) {
            if (a.getClass().getName().equals(str)) {
                a.finish();
            }
        }
    }

    public static void finishSameLesOne(Class glass) {
        String str = glass.getName();
        boolean b = false;
        for (Activity a : list) {
            if(b&&a.getClass().getName().equals(str)){
                a.finish();
                continue;
            }
            if (a.getClass().getName().equals(str)) {
                b=true;
            }
        }
    }

    public static void finishOthers(Class glass) {
        String str = glass.getName();
        for (Activity a : list) {
            if (!a.getClass().getName().equals(str)) {
                a.finish();
            }
        }
    }

    public static void exit() {
        for (Activity a : list) {
            a.finish();
        }
    }

    public static Activity getActivity(Class glass) {
        String str = glass.getName();
        for (Activity a : list) {
            if (a.getClass().getName().equals(str)) return a;
        }
        return null;
    }


    public static void startBaseWebActivity(Activity activity, String title, String url) {
        Intent intent = new Intent(activity, BaseWebviewActivity.class);
        intent.putExtra("topTitle", title);
        intent.putExtra("url", url);
        activity.startActivity(intent);
    }

    public static void startBaseWebActivity(Activity activity, String title, String url, boolean share) {
        Intent intent = new Intent(activity, BaseWebviewActivity.class);
        intent.putExtra("isShare", share);
        intent.putExtra("topTitle", title);
        intent.putExtra("url", url);
        activity.startActivity(intent);
    }
}
